<template>
  <!-- 登录界面 -->
  <div class="login">
    <!-- 返回按钮 -->
    <div class="back">
      <img src="../assets/image/left.png" alt="" @click="$router.go(-1)" />
    </div>
    <div class="bg_text">
      <p>Welcome to...</p>
      <p>Hotel interior environment elegant, complete supporting facilities</p>
    </div>
    <div class="bg">
      <img src="/mine/bg.png" />
    </div>

    <template>
      <div class="login_box">
        <van-cell-group>
          <van-field
            v-model="user"
            placeholder="请输入手机号 / 用户名"
          ></van-field>
          <van-field
            v-model="pwd"
            type="password"
            placeholder="请输入密码"
          ></van-field>
        </van-cell-group>
      </div>
      <div class="toReg">
        还没有账号?<span style="color: #f5b400" @click="toReg">立即注册</span>
      </div>
      <van-button class="btnLogin" @click="toLogin">登录</van-button>
    </template>
    <van-divider solid class="p">选择其他方式登录</van-divider>
    <div class="icon">
      <div class="icon_box">
        <img src="../assets/image/QQ.png" alt="" />
      </div>
      <div class="icon_box">
        <img src="../assets/image/weixin.png" alt="" />
      </div>
      <div class="icon_box">
        <img src="../assets/image/weibo.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
import { Form, Toast } from "vant";
export default {
  data() {
    return {
      user: "",
      pwd: "",
    };
  },
  methods: {
    toReg() {
      this.$router.push("/register");
    },
    // 登录验证
    toLogin() {
      let exp = /^1[34578]\d{9}$/;
      let params = "";
      if (exp.test(this.user)) {
        params = `phone=${this.user}&password=${this.pwd}`;
      } else {
        params = `username=${this.user}&password=${this.pwd}`;
      }
      this.axios.post("/users/login", params).then((res) => {
        if (res.data.code == 200) {
          Toast.success("登录成功");
          sessionStorage.setItem("uid", res.data.result.uid);
          setTimeout(() => {
            this.$router.push("/");
          }, 1000);
        } else {
          Toast.fail("登陆失败");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  text-align: center;
  position: relative;
  .back {
    position: absolute;
    left: 4vw;
    top: 2vh;
    width: 30px;
    img {
      width: 100%;
    }
  }
  .bg_text {
    position: absolute;
    color: #fff;
    z-index: 1;
    left: 10vw;
    top: 3vh;
    text-align: left;
    p:first-child {
      font-size: 34px;
      margin: 60px 0 10px 0px;
      font-weight: 600;
    }
    p:last-child {
      font-size: 12px;
      letter-spacing: 1px;
      margin: 10px 0;
      font-weight: 300;
    }
  }
  .bg {
    width: 100vw;
    border-radius: 10px;
    img {
      width: 100%;
      height: 45vh;
      border-radius: 0 0 0 40px;
    }
  }
  .login_box {
    position: fixed;
    top: 35vh;
    left: 10vw;
    margin: 0 auto;
    width: 80vw;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba($color: #000, $alpha: 0.15);
    .van-hairline--top-bottom::after {
      border: 0;
    }
    div {
      border-radius: 20px;
      div {
        padding: 3.3vh 3.5vh;
        font-size: 16px;
      }
    }
  }
  .toReg {
    margin: 0 auto;
    color: #666;
    margin-top: 24vh;
    z-index: 100;
  }
  .btnLogin {
    position: fixed;
    top: 60vh;
    left: 10vw;
    background-color: #f5b400;
    color: #fff;
    border-radius: 10px;
    width: 80vw;
    height: 48px;
    font-size: 16px;
    outline: none;
  }
  .p {
    position: fixed;
    left: 10vw;
    bottom: 14vh;
    color: #666;
    width: 80vw;
    text-align: center;
    font-size: 12px;
  }
  .icon {
    position: fixed;
    bottom: 6vh;
    display: flex;
    justify-content: center;
    width: 100vw;
    text-align: center;
    .icon_box {
      width: 60px;
      height: 60px;
      border-radius: 30%;
      margin: 0 15px;
      box-shadow: 0 10px 20px rgba($color: #000, $alpha: 0.15);
      display: flex;
      align-items: center;
      img {
        width: 60%;
        display: block;
        margin: 0 auto;
      }
    }
  }
  .reg_box {
    position: fixed;
    top: 8vh;
    left: 10vw;
    margin: 0 auto;
    width: 80vw;
    border-radius: 20px;
    box-shadow: 0 10px 20px rgba($color: #000, $alpha: 0.15);
    z-index: 1;
    .van-hairline--top-bottom::after {
      border: 0;
    }
    div {
      border-radius: 20px;
      div {
        padding: 3vh 3.5vh;
        font-size: 16px;
      }
      .send_yzm {
        padding: 0;
        background-color: #f5b400;
        color: #fff;
        width: 25vw;
        border: 0;
        .van-button__content {
          padding: 0;
          font-size: 14px;
        }
      }
    }
  }
  .btnReg {
    position: fixed;
    top: 68vh;
    left: 10vw;
    background-color: #f5b400;
    color: #fff;
    border-radius: 10px;
    width: 80vw;
    height: 48px;
    font-size: 16px;
    outline: none;
  }
  .check_box {
    position: fixed;
    top: 63vh;
    left: 12vw;
    font-size: 14px;
  }
  .toLog {
    position: fixed;
    top: 63vh;
    font-size: 14px;
    left: 72vw;
  }
  .block {
    width: 90vw;
    height: 90vh;
    margin: 5vh auto;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    letter-spacing: 1px;
    text-indent: 30px;
    z-index: 300;
    div {
      height: 75vh;
      overflow: auto;
      p {
        padding: 6px 20px;
        color: #333;
        font-size: 14px;
        text-align: left;
      }
    }
    button {
      position: absolute;
      bottom: 20px;
      left: 38%;
      background-color: #f5b400;
      color: #fff;
      div {
        height: 40px;
      }
    }
  }
}
</style>